package Thread;

public class Demo4 {
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                while(true) {
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    }catch (InterruptedException e){
                     throw new RuntimeException(e);
                    }
                }
            }
        };

        Thread t = new Thread(runnable);
        t.start();

        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            }catch (InterruptedException e){
                throw new RuntimeException(e);
            }
        }
/*
上面这段代码最简单的写法

 */
        //直接在定义t的时候进行Runnable接口的匿名内部类的定义
//        Thread t = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                while(true) {
//                    System.out.println("hello thread");
//                    try {
//                        Thread.sleep(1000);
//                    }catch (InterruptedException e){
//                        throw new RuntimeException(e);
//                    }
//                }
//            }
//        };)
//            t.start();
//
//            while(true){
//                System.out.println("hello main");
//                Thread.sleep(1000);
//            }

    }
}

